package com.situ.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.situ.domain.dto.UserPageQueryDTO;
import com.situ.domain.entity.TUser;
import com.situ.domain.vo.BasePageQueryVO;
import com.situ.domain.vo.UserReportVO;
import com.situ.service.UserService;
import com.situ.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;


@Slf4j
@RestController
@Tag(name = "用户接口")
@RequestMapping("/user")
@RequiredArgsConstructor
@SaCheckRole("ROLE_ADMIN")
public class UserController {

    private final UserService userService;

    @GetMapping("/pageQuery")
    @Operation(summary = "分页查询用户列表")
    public Result<BasePageQueryVO<TUser>> searchUsersByPage(@ParameterObject UserPageQueryDTO pageQueryDTO) {
        log.info("分页查询用户列表:{}", pageQueryDTO);
        BasePageQueryVO<TUser> basePageQueryVO = userService.searchUsersByPage(pageQueryDTO);
        return Result.success(200, "获取用户列表成功", basePageQueryVO);
    }


    @PutMapping("/changeStatus/{uid}/{isDelete}")
    @Operation(summary = "修改用户状态")
    public Result changeStatus(@PathVariable Integer uid,@PathVariable  Integer isDelete) {
        log.info("修改用户状态:{},{}", uid,isDelete);
        userService.changeStatus(uid,isDelete);
        return Result.ok("修改用户状态成功");
    }

    @GetMapping("/getUserReport")
    @Operation(summary = "获取用户报表")
    public Result<UserReportVO> getUserReport() {
        UserReportVO userReportVO = userService.geUserReport();
        return Result.success(200, "获取用户报表成功", userReportVO);
    }

}
